﻿using RestAPICore;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace RestAPICore.Test
{
    
    
    /// <summary>
    ///This is a test class for JsonClientHelperTest and is intended
    ///to contain all JsonClientHelperTest Unit Tests
    ///</summary>
    [TestClass()]
    public class JsonClientHelperTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion





        /// <summary>
        ///A test for GetAbsoultUri
        ///</summary>
        [TestMethod()]
        public void GetAbsoultUriTest()
        {
            Uri relativeUri =new Uri( "/a/b" ,UriKind.Relative) ; // TODO: Initialize to an appropriate value
            Uri baseUri = new Uri("http://163.com"); // TODO: Initialize to an appropriate value
           Dictionary<string ,List<string>> queryStringSet =
                new Dictionary<string,List<string>>()                {
                   
                    {"a",new List< string>{ "123"}}
                }; // TODO: Initialize to an appropriate value
            string expected = "http://163.com/a/b?a=123"; // TODO: Initialize to an appropriate value
            string actual;
            actual = JsonClientHelper.GetAbsoultUrl(baseUri, relativeUri, queryStringSet);
            Assert.AreEqual(expected, actual);
            
        }

        [TestMethod()]
        public void GetAbsoultUriTestChineseChars()
        {
            Uri relativeUri = new Uri("/a/b", UriKind.Relative); // TODO: Initialize to an appropriate value
            Uri baseUri = new Uri("http://163.com"); // TODO: Initialize to an appropriate value
            Dictionary<string, List<string>> queryStringSet =
              new Dictionary<string, List<string>>()                {
                   
                    {"a",new List< string>{ "123","采购"}},
                    {"b",new List< string>{ "你好"}}
                }; // TODO: Initialize to an appropriate value
            string expected = "http://163.com/a/b?a=123&a=%E9%87%87%E8%B4%AD&b=%E4%BD%A0%E5%A5%BD"; // TODO: Initialize to an appropriate value
            string actual;
            actual = JsonClientHelper.GetAbsoultUrl(baseUri, relativeUri, queryStringSet);
            Assert.IsTrue(string.Equals( expected, actual, StringComparison.CurrentCultureIgnoreCase));

        }

        const string jsontest = @"[{""a"":[{""a"":[{""a"":{""xxx"":123}}]}]}]";
        [TestMethod()]
        public void TestSpDicNum()
        {
            var stm = new MemoryStream(Encoding.UTF8.GetBytes(jsontest));
            stm.Position = 0;
            var jsonS = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(MyContract.JsonTestTestNumResponse));
            var o = jsonS.ReadObject(stm);
        }
    }
}
